<template>
  <div class="app-container">
    <!-- <son-comp :money="100" :fn="fn" /> -->
    <!-- <son-comp :money="100" :fn="fn" /> -->
    <!--
      上传excel组件
      属性on-success - 当成功的时候触发
      属性before-upload - 上传前
     -->
    <upload-excel
      :on-success="handleSuccess"
      :before-upload="beforeUpload"
    />
    <!-- v-for="item of tableHeader"遍历值 -->
    <el-table :data="tableData" border highlight-current-row style="width: 100%;margin-top:20px;">
      <el-table-column v-for="item of tableHeader" :key="item" :prop="item" :label="item" />
    </el-table>
  </div>
</template>

<script>
// import sonComp from './components/son-comp.vue'
// import sonComp from './components/son-comp.vue'
// import UploadExcelComponent from '@/components/UploadExcel/index.vue'

export default {
  // components: { sonComp },
  // components: { sonComp },
  // name: 'UploadExcel',

  // components: { UploadExcelComponent },
  data() {
    return {
      tableData: [],
      tableHeader: []
    }
  },
  methods: {
    fn({ results, header }) {
      console.log(results, header)
    },
    // fn({ results, header }) {
    //   console.log('看看有没有调用', results, header)
    // },
    beforeUpload(file) {
      // console.log(file)
      // console.log(file.size / 1024 / 1024)
      // 上传前 校验 - 校验了文件大小
    // 校验通过 才会上传
    // 校验没通过 不会上传
      const isLt1M = file.size / 1024 / 1024 < 1
      // file的size 单位是b
      // 1024b = 1kb
      // 1024kb = 1mb
      // 是否小于1兆(mb) true - 小于1兆  false - 大于1兆
      if (isLt1M) {
        return true
      }

      this.$message({
        message: 'Please do not upload files larger than 1m in size.',
        type: 'warning'
      })
      return false
    },
    handleSuccess({ results, header }) {
      // 上传成功时处理 results - 表格里内容结果 header 表头
      // console.log(results, header)
      this.tableData = results
      this.tableHeader = header
    }
  }
}
</script>
